package com.my.commonlibrary.net.netroid;

import com.duowan.mobile.netroid.AuthFailureError;
import com.duowan.mobile.netroid.Listener;
import com.duowan.mobile.netroid.NetworkResponse;
import com.duowan.mobile.netroid.ParseError;
import com.duowan.mobile.netroid.Request;
import com.duowan.mobile.netroid.Response;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.util.Map;

/**
 * Author : Cooper
 * Time : 2016/11/6  14:43
 * Description : netroid post请求
 */

public class NormalPostRequest extends Request<JSONObject> {
    private Map<String, String> mMap;
    private Listener<JSONObject> mListener;

    public NormalPostRequest(String url, Map<String, String> map, Listener<JSONObject> listener) {
        super(1, url, listener);
        this.mListener = listener;
        this.mMap = map;
    }

    public Map<String, String> getParams() throws AuthFailureError {
        return this.mMap;
    }

    protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
        try {
            String je = new String(response.data, response.charset);
            return Response.success(new JSONObject(je), response);
        } catch (UnsupportedEncodingException var3) {
            return Response.error(new ParseError(var3));
        } catch (JSONException var4) {
            return Response.error(new ParseError(var4));
        }
    }
}
